package com.ytktt.study.week7.task10.service.impl;

import com.ytktt.study.week7.task10.entity.DemoEntity;
import com.ytktt.study.week7.task10.mapper.DemoEntityMapper;
import com.ytktt.study.week7.task10.service.DemoService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * demo 业务逻辑实现
 *
 * @author ytk
 */
@Slf4j
@Service
@RequiredArgsConstructor
public class DemoServiceImpl implements DemoService {

    private final DemoEntityMapper demoEntityMapper;

    @Override
    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
    public void save(DemoEntity demoEntity) {
        this.demoEntityMapper.insertSelective(demoEntity);
    }

    @Override
    public List<DemoEntity> listDemo() {
        return this.demoEntityMapper.selectAll();
    }
}
